import { createI18n } from 'vue-i18n'
import en from './en.js';
import zh from './zh.js';

function getLocal() {
	try {
		const myLocale = localStorage.getItem('locale')
		if (myLocale) { return myLocale }
		// 否则读取当前网页语言
		const localName = navigator.language.indexOf('zh') !== -1 ? 'zh' : 'en'
		localStorage.setItem('locale', localName)
		return localName
	} catch (err) {
		return 'zh'
	}
}

export default createI18n({
	legacy: false,
	globalInjection: true,
	locale: getLocal(),
	messages: { en, zh }
})